package ihm;

import java.io.IOException;

import client.CommunicationClient;

/**
 * Classe ThreadConversationClient
 *
 */
public class ThreadConversation extends Thread 
{	
	//email de l'ami avec qui on souhaite discuter
	private String emailAmi;
	//message que l'on souhaite envoyer à cet ami
	private String messageE;
	private CommunicationClient comCl;
	private Conversation conv;
	
	/** Constructeur **/
	public ThreadConversation(String _emailAmi,CommunicationClient _comCl)
	{
		comCl=_comCl;
		emailAmi=_emailAmi.split(" ")[0];
		messageE="";
		conv=new Conversation(emailAmi,this);
	}
	
	/** Methode run() **/
	public void run()
	{	
		comCl.getConversations().add(conv);
		while (true)
		{
			if(messageE!="")
			{
				try 
				{
					conv.affichageTexte(messageE, "moi");
					comCl.envoieMessage(emailAmi, messageE);
					messageE="";
				} catch (IOException e) {e.printStackTrace();}
			}
		}
	}

	/** Methodes get & set **/
	public CommunicationClient getComCl() {
		return comCl;
	}

	public void setComCl(CommunicationClient comCl) {
		this.comCl = comCl;
	}

	public Conversation getConv() {
		return conv;
	}

	public void setConv(Conversation conv) {
		this.conv = conv;
	}

	public String getEmailAmi() {
		return emailAmi;
	}

	public void setEmailAmi(String emailAmi) {
		this.emailAmi = emailAmi;
	}

	public String getMessage() {
		return messageE;
	}

	public void setMessage(String message) {
		this.messageE = message;
	}
	//fin methodes get & set
	
}//fin Classe ThreadConversation
